package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.ExaminationDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Examination;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;


/**
 * []
 *
 * @author : [itnan]
 * @version : [v1.0]
 * @createTime : [2025/2/11 16:10]
 */
@Service(interfaceClass = ExaminationService.class)
public class ExaminationServiceImpl implements ExaminationService {

    @Autowired
    private ExaminationDao examinationDao;
    /**
     * 分页查询所有或条件查询体检预约信息
     *
     * @param queryPageBean
     */
    @Override
    public PageResult findPageOrCondition(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage,pageSize);
        Page<Examination> page = examinationDao.findPageOrCondition(queryString);
        return new PageResult(page.getTotal(), page.getResult());
    }

    /**
     * 添加体检预约信息
     *
     * @param examination
     */
    @Override
    public void add(Examination examination) {
        examination.setUpLoadTime(LocalDateTime.now());
        examinationDao.insertExamination(examination);
    }

    /**
     * 更新体检信息
     *
     * @param examination
     */
    @Override
    public void updateExamination(Examination examination) {
        examinationDao.updateExamination(examination);
    }

    /**
     * 根据体检预约id删除体检预约信息
     *
     * @param id
     */
    @Override
    public void deleteExaminationById(int id) {
        examinationDao.deleteExaminationById(id);
    }

    /**
     * 根据体检预约id查询体检预约信息
     *
     * @param id
     */
    @Override
    public Examination findExaminationById(Integer id) {
        return examinationDao.findExaminationById(id);
    }

    @Override
    public List<Examination> getExaminationReportByTelephone(String telephone) {
        List<Examination> examination = examinationDao.findExaminationByTelephone(telephone);
        return examination;
    }
}
